import { View, TouchableOpacity } from 'react-native';
import React, { useState, useEffect } from 'react';
import AntDesign from 'react-native-vector-icons/AntDesign';
import { Toast } from '@ant-design/react-native';
import MineLogView from '../../components/MineLogView';
import { debounce } from '../../utils/common';
import { selectMineLog } from '../../comconfig/sqlfun';

const MineLog = ({ navigation }) => {
    const [logList, setLogList] = useState([]);
    const getLogList = async () => {
        try {
            const list = await selectMineLog();
            const arr = [];
            for (let i = 0; i < list.length; i += 1) {
                arr.push(JSON.parse(list[i]));
            }
            setLogList(arr);
        } catch (error) {
            Toast.info('获取数据失败', 1, undefined, false);
        }
    };
    useEffect(() => {
        getLogList();
    }, []);
    navigation.setOptions({
        headerRight: () => (
            <TouchableOpacity
                onPress={() => {
                    debounce(() => navigation.push('添加日志', { isEditing: false, getLogList }));
                }}
                style={{ marginRight: 10 }}
            >
                <AntDesign
                    name="form"
                    size={25}
                    color="#0079FF"
                />
            </TouchableOpacity>
        ),
    });
    return (
        <View>
            <MineLogView navigation={navigation} logList={logList} getLogList={getLogList} />
        </View>
    );
};

export default MineLog;
